﻿using System.IO;
using Mockery.Core;
using NUnit.Framework;
using Rhino.Mocks;

namespace Mockery.UnitTest
{
    [TestFixture]
    public class MockeryTests
    {
        [Test]
        public void Mockery_ContextSetupTest()
        {
            Mockery<MockeryTests> mockeryInstance = null;

            InjectedTest.Target<Mockery<MockeryTests>>(
                tgt => mockeryInstance = tgt.ContextSetup(() => new MemoryStream()))
                    .Arrange(a => a.AddStub<IArranger>()
                                   .AddStub<ITypeCache>()
                                   .AddStub<IActiveMockeryState>()
                                   .AddStub<IMockeryStateEvents>()
                                   .AddStrictMock<IDisposableContextState>()
                                   .ExpectOn<IDisposableContextState>(e => Expect.Call(() => e.Add(new MemoryStream())).IgnoreArguments()))
                .Assert( () =>Assert.That(mockeryInstance != null));
        }

        [Test]
        public void Mockery_ContextSetupActionTest()
        {
            var x = 0;

            InjectedTest.Target<Mockery<MockeryTests>>( tgt => tgt.ContextSetup(() => x++))
                .Arrange(a => a.AddStub<IArranger>()
                               .AddStub<ITypeCache>()
                               .AddStub<IActiveMockeryState>()
                               .AddStub<IMockeryStateEvents>()
                               .AddStub<IDisposableContextState>())
                .Assert(() => Assert.That(x == 1));
        }

        [Test]
        public void Mockery_ContextTeardownActionTest()
        {
            var x = 0;

            InjectedTest.Target<Mockery<MockeryTests>>(tgt => tgt.ContextTeardown(() => x++))
                .Arrange(a => a.AddStub<IArranger>()
                               .AddStub<ITypeCache>()
                               .AddStub<IActiveMockeryState>()
                               .AddStub<IMockeryStateEvents>()
                               .AddStub<IDisposableContextState>())
                .Assert(() => Assert.That(x == 1));
        }

        [Test]
        public void Mockery_EmptyAssertTest()
        {
            InjectedTest.Target<Mockery<MockeryTests>>(a => a.Assert())
                .Arrange(a => a.AddStub<IArranger>()
                               .AddStub<ITypeCache>()
                               .AddStub<IMockeryStateEvents>()
                               .AddStub<IDisposableContextState>()
                               .AddStrictMock<IActiveMockeryState>()
                               .ExpectOn<IActiveMockeryState>(e => Expect.Call(() => e.SetState(MockeryState.Assert))))
                .Assert();
        }


    }
}
